package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.CancelNursingTaskDto;
import com.zzyl.nursing.dto.TaskDto;
import com.zzyl.nursing.dto.pageDto;
import com.zzyl.nursing.vo.NursingTaskDetailVO;
import com.zzyl.nursing.vo.pageVO;
import com.zzyl.nursing.vo.NursingTaskVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.service.INursingTaskService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理任务Controller
 * 
 * @author zzyl
 * @date 2025-10-29
 */
@RestController
@RequestMapping("/nursing/nursingTask")
@Api(tags = "护理任务相关接口")
public class NursingTaskController extends BaseController
{
    @Autowired
    private INursingTaskService nursingTaskService;

    /**
     * 查询护理任务列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取护理任务列表")
    public TableDataInfo<List<pageVO >> list(pageDto nursingTask)
    {
//        startPage();
        List<pageVO> nursingTasks = nursingTaskService.selectNursingTaskList(nursingTask);
        return getDataTable(nursingTasks);
    }

//    /**
//     * 导出护理任务列表
//     */
//    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:export')")
//    @Log(title = "护理任务", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ApiOperation("导出护理任务列表")
//    public void export(HttpServletResponse response, pageDto dto)
//    {
//        List<NursingTask> list = nursingTaskService.selectNursingTaskList(dto);
//        ExcelUtil<NursingTask> util = new ExcelUtil<NursingTask>(NursingTask.class);
//       util.exportExcel(response, list, "护理任务数据");
//    }

    /**
     * 获取护理任务详细信息
     * @param id 护理任务ID
     * @return 护理任务详情
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "获取护理任务详细信息", notes = "根据任务ID查询单个护理任务的完整信息")
    @ApiImplicitParam(name = "id", value = "护理任务ID", required = true, dataType = "Long", paramType = "path")
    public AjaxResult getNursingTaskDetail(
            @PathVariable @NotNull(message = "任务ID不能为空") Long id) {
        // 调用服务层查询任务详情
        NursingTaskDetailVO nursingTaskDetail = nursingTaskService.getNursingTaskById(id);
        // 返回成功响应，封装任务数据
        return AjaxResult.success(nursingTaskDetail);
    }

    /**
     * 新增护理任务
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:add')")
    @Log(title = "护理任务", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增护理任务")
    public AjaxResult add(@ApiParam(value = "护理任务实体", required = true) @RequestBody NursingTask nursingTask)
    {
        return toAjax(nursingTaskService.insertNursingTask(nursingTask));
    }

    /**
     * 修改护理任务
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:edit')")
    @Log(title = "护理任务", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改护理任务")
    public AjaxResult edit(@ApiParam(value = "护理任务实体", required = true) @RequestBody NursingTask nursingTask)
    {
        return toAjax(nursingTaskService.updateNursingTask(nursingTask));
    }

    /**
     * 删除护理任务
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:remove')")
    @Log(title = "护理任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除护理任务")
    public AjaxResult remove(@ApiParam(value = "要删除的数据id的数组") @PathVariable Long[] ids)
    {
        return toAjax(nursingTaskService.deleteNursingTaskByIds(ids));
    }

    /**
     * 执行任务
     * @param task
     * @return
     */
    @PutMapping("/do")
    @ApiOperation("执行任务")
    public AjaxResult doTask(@RequestBody TaskDto task){
        nursingTaskService.doTask(task);
        return success();
    }

    /**
     * 取消护理任务
     */
    @PutMapping("/cancel")
    @ApiOperation("取消护理任务")
    public AjaxResult cancelNursingTask(@RequestBody CancelNursingTaskDto dto){
        nursingTaskService.cancelNursingTask(dto);
        return success();
    }
}
